package com.data.filter;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author: wangmq
 * @create: 2024-01-08 11:49
 **/
@Component
public class MyFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("----------------MyfilterInit----------------");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //在DispatcherServlet之前执行
        System.out.println("############TestFilter3 doFilterInternal executed############");
        filterChain.doFilter(servletRequest, servletResponse);
        //在视图页面返回给客户端之前执行，但是执行顺序在Interceptor之后
        System.out.println("############TestFilter3 doFilter after############");
    }

    @Override
    public void destroy() {
        System.out.println("----------------Myfilter Destroy----------------");
    }
}
